<?php
namespace app\common\model;

class ShopGoodsDataModel extends BaseModel
{
    protected $name = 'shop_goods_data'; //定义栏目表
    //开启自动写入时间戳
    protected $autoWriteTimestamp = false;
    // 定义自动完成的属性
    protected $auto = []; //新增修改
    protected $insert = []; //插入
    protected $update = []; //修改
    /*读取器*/

    public function getExtendAttr($value, $data)
    {
        if (empty($data['extend'])) return '';
        $data['extend'] = explode(",", $data['extend']);
        $result         = [];
        foreach ($data['extend'] as $k => $v) {
            $v          = explode(":", $v);
            $result[$k] = ['key' => $v[0], 'value' => $v[1]];
        }
        return $result;
    }

    /*修改器*/
    protected function setGoodsExtendAttr($value, $data)
    {
        if ($data['goods_extend']) {
            foreach ($data['goods_extend']['key'] as $k => $v) {
                $key = str_replace(':','：',$v);
                $key = str_replace(',','，',$key);
                $value = str_replace(':','：',$data['goods_extend']['value'][$k]);
                $value = str_replace(',','，',$value);
                $list[$k] = $key . ":" . $value;
            }
            $list = implode(",", $list);
            return $list;
        }
        return '';
    }
    protected function getContentAttr($value)
    {
        return stripslashes(htmlspecialchars_decode($value));
    }
}
